<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/8/6
  Time: 16:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>添加科目</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="${AppPath}/css/font.css">
    <link rel="stylesheet" href="${AppPath}/css/index.css">
    <script type="text/javascript" src="${AppPath}/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${AppPath}/js/index.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->

</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form" id="form">
            <div class="layui-form-item">
                <label for="courseName" class="layui-form-label">
                    <span class="x-red">*</span>科目名称
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="courseName" name="courseName" required="" lay-verify="courseName"
                           autocomplete="off" class="layui-input" onblur="course()">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>科目名称
                </div>
                <label class="layui-form-label" id="courseNamemsg">

                </label>
            </div>
            <div class="layui-form-item">
                <label for="courseDetail" class="layui-form-label">
                    <span class="x-red">*</span>科目简介
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="courseDetail" name="courseDetail" required="" lay-verify="courseDetail"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    简介
                </div>
            </div>
            <div class="layui-form-item">
                <label for="courseAttribute" class="layui-form-label">
                    <span class="x-red">*</span>科目属性
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="courseAttribute" name="courseAttribute" required="" lay-verify="courseAttribute"
                           autocomplete="off" class="layui-input" onblur="courseA()">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>科目属性
                </div>
                <label class="layui-form-label" id="courseAttributemsg">

                </label>
            </div>
            <%--<div class="layui-form-item">
                <label class="layui-form-label"><span class="x-red">*</span>角色</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="like1[write]" lay-skin="primary" title="超级管理员" checked="">
                    <input type="checkbox" name="like1[read]" lay-skin="primary" title="编辑人员">
                    <input type="checkbox" name="like1[write]" lay-skin="primary" title="宣传人员" checked="">
                </div>
            </div>--%>
            <div class="layui-form-item">
                <label for="courseScore" class="layui-form-label">
                    <span class="x-red">*</span>学分
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="courseScore" name="courseScore" required="" lay-verify="courseScore"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    学分
                </div>
            </div>
            <div class="layui-form-item">
                <label for="courseStartTime" class="layui-form-label">
                    <span class="x-red">*</span>开课时间
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="courseStartTime" name="courseStartTime" required="" lay-verify="courseStartTime"
                           autocomplete="off" class="layui-input" onblur="courseS()">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>开课时间
                </div>
                <label class="layui-form-label" id="courseStartTimemsg">

                </label>
            </div>
            <div class="layui-form-item">
                <label for="courseTotal" class="layui-form-label">
                    <span class="x-red">*</span>学时
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="courseTotal" name="courseTotal" required="" lay-verify="courseTotal"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    学时
                </div>
            </div>
            <div class="layui-form-item">
                <label for="courseTotal" class="layui-form-label">
                </label>
                <button  class="layui-btn" type="button" lay-filter="add" lay-submit="" id="addBtn">
                    增加
                </button>
            </div>
        </form>
    </div>
</div>
<script src="${AppPath}/js/jquery.js"></script>
<script>layui.use(['form', 'layer','laydate'],
    function() {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;
        var laydate = layui.laydate;


        //自定义验证规则
        form.verify({
            nikename: function(value) {
                if (value.length < 5) {
                    return '昵称至少得5个字符啊';
                }
            },
            pass: [/(.+){6,12}$/, '密码必须6到12位'],
            repass: function(value) {
                if ($('#L_pass').val() != $('#L_repass').val()) {
                    return '两次密码不一致';
                }
            }
        });

        //开课时间
        laydate.render({
            elem: '#courseStartTime' //指定元素
            ,trigger: 'click'
        });
        //监听提交
        $("#addBtn").click(function(){
            if(checkmsg()){
                $.ajax({
                    url:"${AppPath}/course/add",
                    data:$("#form").serialize(),
                    type:"post",
                    success: function(data){
                        if(data.result){
                            layer.msg("增加成功",{time:2000,icon:6},function () {
                                //关闭当前frame
                                xadmin.close();
                                //重新定位到查询页面
                                xadmin.father_reload();
                            })
                        }else{
                            layer.msg("增加失败",{time:2000,icon:5,shift:6});
                        }
                    }
                })
            }

        })

    });
/*表单校验*/
function checkmsg() {
    return course()&&courseA()&&courseS();
}

function  course(){
    let courseName = $("#courseName").val();
    let msg = "<font color='red'>科目不能为空</font>";
    let flag=false;
    if (courseName!=null&&courseName!='') {
        msg = "<font color='green'>ok</font>";
        flag=true;
    }
    $("#courseNamemsg").html(msg);
    return flag;
}
function  courseA(){
    let courseAttribute = $("#courseAttribute").val();
    let msg = "<font color='red'>科目属性不能为空</font>";
    let flag=false;
    if (courseAttribute!=null&&courseAttribute!='') {
        msg = "<font color='green'>ok</font>";
        flag=true;
    }
    $("#courseAttributemsg").html(msg);
    return flag;
}
function  courseS(){
    let courseStartTime = $("#courseStartTime").val();
    let msg = "<font color='red'>开课时间不能为空</font>";
    let flag=false;
    if (courseStartTime!=null&&courseStartTime!='') {
        msg = "<font color='green'>ok</font>";
        flag=true;
    }
    $("#courseStartTimemsg").html(msg);
    return flag;
}
</script>
<script>var _hmt = _hmt || []; (function() {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
})();</script>
</body>

</html>

